﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class QltaoTK : Form
    {
        public QltaoTK()
        {
            InitializeComponent();
        }

        private DataTable _dSNV;

        internal DataTable DSNV
        {
            get { return _dSNV; }
            set { _dSNV = value; }
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void QltaoTK_Load(object sender, EventArgs e)
        {
            DSNV = BUS.XuLyTaiKhoan.TimDSNVChuaTaoTK();
            dgvDSNV.DataSource = DSNV;
        }

        private void dgvDSNV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dgvDSNV.SelectedRows[0].Index;

            DataRow dr = DSNV.Rows[index];
            txtMaNV.Text = dr["MaNhanVien"].ToString();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (dgvDSNV.SelectedRows.Count > 0)
            {
                if ((txtPass.Text == "") || (txtUser.Text == ""))
                {
                    MessageBox.Show("Ban chua nhap ten tai khoan hay password");
                }
                else
                {
                    String MD5Pass = BUS.XuLyTaiKhoan.getMd5Hash(txtPass.Text);
                    DTO.CTAIKHOAN tk = new DTO.CTAIKHOAN();
                    tk.MaNhanVien = int.Parse(txtMaNV.Text);
                    tk.Username = txtUser.Text;
                    tk.Password = MD5Pass;

                    if (!(BUS.XuLyTaiKhoan.ThemTaiKhoan(tk)))
                        MessageBox.Show("Loi CSDL. Kiem tra lai file DB");
                    this.Close();
                }
            } 
            else
            {
                MessageBox.Show("Ban chua chon nhan vien");
            }
        }
    }
}
